 package net.go176.backpack.util.simplenbt;
 
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.Field;
 import java.lang.reflect.Method;
 import java.util.HashMap;
 import java.util.Map;
 import org.bukkit.entity.Entity;
 import org.bukkit.inventory.ItemStack;
 
 
 public class Reflector
 {
   private static Class<?> clazzNBTBase = null;
   private static Method nbtbaseGetTypeId = null;
 
   
   private static Class<?> clazzNBTTagCompound = null;
   private static Method nbttcHasKey = null;
   private static Method nbttcGet = null;
   private static Method nbttcRemove = null;
   private static Method nbttcSet = null;
   
   private static Class<?> clazzNBTTagList = null;
   private static Method nbtlistSize = null;
   private static Method nbtlistGet = null;
   private static Method nbtlistAdd = null;
   
   private static Class<?> clazzNBTNumber = null;
   private static Method nbtnumLongValue = null;
   private static Method nbtnumIntValue = null;
   private static Method nbtnumShortValue = null;
   private static Method nbtnumByteValue = null;
   private static Method nbtnumDoubleValue = null;
   private static Method nbtnumFloatValue = null;
   
   private static Class<?> clazzNBTTagByte = null;
   private static Constructor<?> consNBTTagByte = null;
   
   private static Method readCompressedNBT = null;
   private static Method writeCompressedNBT = null;
   
   private static Method createStack = null;
   private static Method saveStackToNBT = null;
   private static Method asNMSCopy = null;
   private static Method asCraftMirror = null;
   private static Method getNMSEntity = null;
   private static Method readFromNBT = null;
   private static Method writeToNBT = null;
   
   public static void initReflector(String obcVersion, boolean isMCPServer) throws ClassNotFoundException, NoSuchMethodException, SecurityException {
     String nms = isMCPServer ? "net.minecraft" : ("net.minecraft.server." + obcVersion);
     String obc = "org.bukkit.craftbukkit." + obcVersion;
     String[] split = obcVersion.substring(1).split("_");
     int ver1 = Integer.parseInt(split[0]);
     int ver2 = Integer.parseInt(split[1]);
     
     clazzNBTBase = Class.forName(String.valueOf(nms) + (isMCPServer ? ".nbt" : "") + ".NBTBase");
     nbtbaseGetTypeId = clazzNBTBase.getDeclaredMethod(isMCPServer ? "func_74732_a" : "getTypeId", new Class[0]);
 
 
     
     clazzNBTTagCompound = Class.forName(String.valueOf(nms) + (isMCPServer ? ".nbt" : "") + ".NBTTagCompound");
     nbttcHasKey = clazzNBTTagCompound.getDeclaredMethod(isMCPServer ? "func_74764_b" : "hasKey", new Class[] { String.class });
     nbttcGet = clazzNBTTagCompound.getDeclaredMethod(isMCPServer ? "func_74781_a" : "get", new Class[] { String.class });
     nbttcRemove = clazzNBTTagCompound.getDeclaredMethod(isMCPServer ? "func_82580_o" : "remove", new Class[] { String.class });
     nbttcSet = clazzNBTTagCompound.getDeclaredMethod(isMCPServer ? "func_74782_a" : "set", new Class[] { String.class, clazzNBTBase });
     
     clazzNBTTagList = Class.forName(String.valueOf(nms) + (isMCPServer ? ".nbt" : "") + ".NBTTagList");
     nbtlistSize = clazzNBTTagList.getDeclaredMethod(isMCPServer ? "func_74745_c" : "size", new Class[0]);
     nbtlistGet = clazzNBTTagList.getDeclaredMethod(isMCPServer ? "func_150305_b" : "get", new Class[] { int.class });
     nbtlistAdd = clazzNBTTagList.getDeclaredMethod(isMCPServer ? "func_74742_a" : "add", new Class[] { clazzNBTBase });
     System.out.println(nms);
     try {
       if (ver1 == 1)
       { if (isMCPServer) {
           clazzNBTNumber = Class.forName(String.valueOf(nms) + ".nbt.NBTBase$NBTPrimitive");
         } else if (ver2 == 7 || ver2 == 10) {
           clazzNBTNumber = Class.forName(String.valueOf(nms) + ".NBTNumber");
         } else if (ver2 >= 8) {
           clazzNBTNumber = Class.forName(String.valueOf(nms) + ".NBTBase$NBTNumber");
         }  }
       else { clazzNBTNumber = Class.forName(String.valueOf(nms) + (isMCPServer ? ".nbt.NBTBase$NBTPrimitive" : ".NBTBase$NBTNumber")); } 
     } catch (ClassNotFoundException classNotFoundException) {}
     if (clazzNBTNumber != null) {
       nbtnumLongValue = clazzNBTNumber.getDeclaredMethod(isMCPServer ? "func_150291_c" : ((ver2 >= 10) ? "d" : "c"), new Class[0]);
       nbtnumLongValue.setAccessible(true);
       nbtnumIntValue = clazzNBTNumber.getDeclaredMethod(isMCPServer ? "func_150287_d" : ((ver2 >= 10) ? "e" : "d"), new Class[0]);
       nbtnumIntValue.setAccessible(true);
       nbtnumShortValue = clazzNBTNumber.getDeclaredMethod(isMCPServer ? "func_150289_e" : ((ver2 >= 10) ? "f" : "e"), new Class[0]);
       nbtnumShortValue.setAccessible(true);
       nbtnumByteValue = clazzNBTNumber.getDeclaredMethod(isMCPServer ? "func_150290_f" : ((ver2 >= 10) ? "g" : "f"), new Class[0]);
       nbtnumByteValue.setAccessible(true);
       nbtnumDoubleValue = clazzNBTNumber.getDeclaredMethod(isMCPServer ? "func_150286_g" : ((ver2 >= 10) ? "h" : "g"), new Class[0]);
       nbtnumDoubleValue.setAccessible(true);
       nbtnumFloatValue = clazzNBTNumber.getDeclaredMethod(isMCPServer ? "func_150288_h" : ((ver2 >= 10) ? "i" : "h"), new Class[0]);
       nbtnumFloatValue.setAccessible(true);
     } else {
       throw new ClassNotFoundException("NBTNumber");
     } 
     clazzNBTTagByte = Class.forName(String.valueOf(nms) + (isMCPServer ? ".nbt" : "") + ".NBTTagByte");
     consNBTTagByte = clazzNBTTagByte.getConstructor(new Class[] { byte.class });
     
     Class<?> clazzStreamTool = Class.forName(String.valueOf(nms) + (isMCPServer ? ".nbt.CompressedStreamTools" : ".NBTCompressedStreamTools"));
     readCompressedNBT = clazzStreamTool.getDeclaredMethod(isMCPServer ? "func_74796_a" : "a", new Class[] { InputStream.class });
     writeCompressedNBT = clazzStreamTool.getDeclaredMethod(isMCPServer ? "func_74799_a" : "a", new Class[] { clazzNBTTagCompound, OutputStream.class });
     
     Class<?> clazzItemStack = Class.forName(String.valueOf(nms) + (isMCPServer ? ".item" : "") + ".ItemStack");
     createStack = clazzItemStack.getDeclaredMethod(isMCPServer ? "func_77949_a" : "createStack", new Class[] { clazzNBTTagCompound });
     saveStackToNBT = clazzItemStack.getDeclaredMethod(isMCPServer ? "func_77955_b" : "save", new Class[] { clazzNBTTagCompound });
     Class<?> clazzCraftItemStack = Class.forName(String.valueOf(obc) + ".inventory.CraftItemStack");
     asNMSCopy = clazzCraftItemStack.getDeclaredMethod("asNMSCopy", new Class[] { ItemStack.class });
     asCraftMirror = clazzCraftItemStack.getDeclaredMethod("asCraftMirror", new Class[] { clazzItemStack });
     
     Class<?> clazzCraftEntity = Class.forName(String.valueOf(obc) + ".entity.CraftEntity");
     getNMSEntity = clazzCraftEntity.getDeclaredMethod("getHandle", new Class[0]);
     Class<?> clazzEntity = Class.forName(String.valueOf(nms) + (isMCPServer ? ".entity" : "") + ".Entity");
     readFromNBT = clazzEntity.getDeclaredMethod(isMCPServer ? "func_70020_e" : "a", new Class[] { clazzNBTTagCompound });
     readFromNBT.setAccessible(true);
     writeToNBT = clazzEntity.getDeclaredMethod(isMCPServer ? "func_70109_d" : "b", new Class[] { clazzNBTTagCompound });
     writeToNBT.setAccessible(true);
   }
   
   public static byte nbtbaseGetTypeId(Object nbtbase) {
     try {
       return ((Byte)nbtbaseGetTypeId.invoke(nbtbase, new Object[0])).byteValue();
     } catch (Exception e) {
       if (e instanceof RuntimeException)
         throw (RuntimeException)e; 
       throw new RuntimeException(e);
     } 
   }
 
 
 
 
 
 
 
 
 
 
   
   public static Object newNBTTagCompound() {
     try {
       return clazzNBTTagCompound.newInstance();
     } catch (Exception e) {
       if (e instanceof RuntimeException)
         throw (RuntimeException)e; 
       throw new RuntimeException(e);
     } 
   }
   
   public static boolean nbttcHasKey(Object nbttagcompound, String key) {
     try {
       return ((Boolean)nbttcHasKey.invoke(nbttagcompound, new Object[] { key })).booleanValue();
     } catch (Exception e) {
       if (e instanceof RuntimeException)
         throw (RuntimeException)e; 
       throw new RuntimeException(e);
     } 
   }
   
   public static Object nbttcGet(Object nbttagcompound, String key) {
     try {
       return nbttcGet.invoke(nbttagcompound, new Object[] { key });
     } catch (Exception e) {
       if (e instanceof RuntimeException)
         throw (RuntimeException)e; 
       throw new RuntimeException(e);
     } 
   }
   
   public static void nbttcRemove(Object nbttagcompound, String key) {
     try {
       nbttcRemove.invoke(nbttagcompound, new Object[] { key });
     } catch (Exception e) {
       if (e instanceof RuntimeException)
         throw (RuntimeException)e; 
       throw new RuntimeException(e);
     } 
   }
   
   public static Object nbttcSet(Object nbttagcompound, String key, Object nbtbase) {
     try {
       return nbttcSet.invoke(nbttagcompound, new Object[] { key, nbtbase });
     } catch (Exception e) {
       if (e instanceof RuntimeException)
         throw (RuntimeException)e; 
       throw new RuntimeException(e);
     } 
   }
   
   public static Object newNBTTagList() {
     try {
       return clazzNBTTagList.newInstance();
     } catch (Exception e) {
       if (e instanceof RuntimeException)
         throw (RuntimeException)e; 
       throw new RuntimeException(e);
     } 
   }
   
   public static int nbtlistSize(Object nbttaglist) {
     try {
       return ((Integer)nbtlistSize.invoke(nbttaglist, new Object[0])).intValue();
     } catch (Exception e) {
       if (e instanceof RuntimeException)
         throw (RuntimeException)e; 
       throw new RuntimeException(e);
     } 
   }
   
   public static Object nbtlistGet(Object nbttaglist, int i) {
     try {
       return nbtlistGet.invoke(nbttaglist, new Object[] { Integer.valueOf(i) });
     } catch (Exception e) {
       if (e instanceof RuntimeException)
         throw (RuntimeException)e; 
       throw new RuntimeException(e);
     } 
   }
   
   public static void nbtlistAdd(Object nbttaglist, Object nbtbase) {
     try {
       nbtlistAdd.invoke(nbttaglist, new Object[] { nbtbase });
     } catch (Exception e) {
       if (e instanceof RuntimeException)
         throw (RuntimeException)e; 
       throw new RuntimeException(e);
     } 
   }
   
   public static long nbtnumLongValue(Object nbtnumber) {
     try {
       return ((Long)nbtnumLongValue.invoke(nbtnumber, new Object[0])).longValue();
     } catch (Exception e) {
       if (e instanceof RuntimeException)
         throw (RuntimeException)e; 
       throw new RuntimeException(e);
     } 
   }
   
   public static int nbtnumIntValue(Object nbtnumber) {
     try {
       return ((Integer)nbtnumIntValue.invoke(nbtnumber, new Object[0])).intValue();
     } catch (Exception e) {
       if (e instanceof RuntimeException)
         throw (RuntimeException)e; 
       throw new RuntimeException(e);
     } 
   }
   
   public static short nbtnumShortValue(Object nbtnumber) {
     try {
       return ((Short)nbtnumShortValue.invoke(nbtnumber, new Object[0])).shortValue();
     } catch (Exception e) {
       if (e instanceof RuntimeException)
         throw (RuntimeException)e; 
       throw new RuntimeException(e);
     } 
   }
   
   public static byte nbtnumByteValue(Object nbtnumber) {
     try {
       return ((Byte)nbtnumByteValue.invoke(nbtnumber, new Object[0])).byteValue();
     } catch (Exception e) {
       if (e instanceof RuntimeException)
         throw (RuntimeException)e; 
       throw new RuntimeException(e);
     } 
   }
   
   public static double nbtnumDoubleValue(Object nbtnumber) {
     try {
       return ((Double)nbtnumDoubleValue.invoke(nbtnumber, new Object[0])).doubleValue();
     } catch (Exception e) {
       if (e instanceof RuntimeException)
         throw (RuntimeException)e; 
       throw new RuntimeException(e);
     } 
   }
   
   public static float nbtnumFloatValue(Object nbtnumber) {
     try {
       return ((Float)nbtnumFloatValue.invoke(nbtnumber, new Object[0])).floatValue();
     } catch (Exception e) {
       if (e instanceof RuntimeException)
         throw (RuntimeException)e; 
       throw new RuntimeException(e);
     } 
   }
   
   private static Map<Class<?>, Field> nbtnumDataFields = new HashMap<>();
   
   public static Object nbtnumData(Object nbtnumber) {
     try {
       Field nbtnumData = nbtnumDataFields.get(nbtnumber.getClass());
       if (nbtnumData == null) {
         nbtnumData = nbtnumber.getClass().getDeclaredFields()[0];
         nbtnumData.setAccessible(true);
         nbtnumDataFields.put(nbtnumber.getClass(), nbtnumData);
       } 
       return nbtnumData.get(nbtnumber);
     } catch (Exception e) {
       if (e instanceof RuntimeException)
         throw (RuntimeException)e; 
       throw new RuntimeException(e);
     } 
   }
   
   public static Object newNBTTagByte(byte data) {
     try {
       return consNBTTagByte.newInstance(new Object[] { Byte.valueOf(data) });
     } catch (Exception e) {
       if (e instanceof RuntimeException)
         throw (RuntimeException)e; 
       throw new RuntimeException(e);
     } 
   }
   
   public static Object readCompressedNBT(InputStream input) throws IOException {
     try {
       return readCompressedNBT.invoke((Object)null, new Object[] { input });
     } catch (Exception e) {
       if (e instanceof IOException)
         throw (IOException)e; 
       if (e instanceof RuntimeException)
         throw (RuntimeException)e; 
       throw new RuntimeException(e);
     } 
   }
   
   public static void writeCompressedNBT(Object nbt, OutputStream output) throws IOException {
     try {
       writeCompressedNBT.invoke((Object)null, new Object[] { nbt, output });
     } catch (Exception e) {
       if (e instanceof IOException)
         throw (IOException)e; 
       if (e instanceof RuntimeException)
         throw (RuntimeException)e; 
       throw new RuntimeException(e);
     } 
   }
   
   public static Object createStack(Object nbttagcompound) {
     try {
       return createStack.invoke((Object)null, new Object[] { nbttagcompound });
     } catch (Exception e) {
       if (e instanceof RuntimeException)
         throw (RuntimeException)e; 
       throw new RuntimeException(e);
     } 
   }
   
   public static Object saveStackToNBT(Object itemstack, Object nbttagcompound) {
     try {
       return saveStackToNBT.invoke(itemstack, new Object[] { nbttagcompound });
     } catch (Exception e) {
       throw new RuntimeException(e);
     } 
   }
   
   public static Object asNMSCopy(ItemStack itemstack) {
     try {
       return asNMSCopy.invoke((Object)null, new Object[] { itemstack });
     } catch (Exception e) {
       throw new RuntimeException(e);
     } 
   }
   
   public static ItemStack asCraftMirror(Object itemstack) {
     try {
       return (ItemStack)asCraftMirror.invoke((Object)null, new Object[] { itemstack });
     } catch (Exception e) {
       throw new RuntimeException(e);
     } 
   }
   
   public static Object getNMSEntity(Entity entity) {
     try {
       return getNMSEntity.invoke(entity, new Object[0]);
     } catch (Exception e) {
       if (e instanceof RuntimeException)
         throw (RuntimeException)e; 
       throw new RuntimeException(e);
     } 
   }
   
   public static void readFromNBT(Object entity, Object nbttagcompound) {
     try {
       readFromNBT.invoke(entity, new Object[] { nbttagcompound });
     } catch (Exception e) {
       if (e instanceof RuntimeException)
         throw (RuntimeException)e; 
       throw new RuntimeException(e);
     } 
   }
   
   public static void writeToNBT(Object entity, Object nbttagcompound) {
     try {
       writeToNBT.invoke(entity, new Object[] { nbttagcompound });
     } catch (Exception e) {
       if (e instanceof RuntimeException)
         throw (RuntimeException)e; 
       throw new RuntimeException(e);
     } 
   }
   
   public static NBTBase asSimpleMirror(Object nbtbase) {
     if (clazzNBTTagByte.isAssignableFrom(nbtbase.getClass()))
       return new NBTTagByte(nbtbase); 
     if (clazzNBTNumber.isAssignableFrom(nbtbase.getClass()))
       return new NBTNumber(nbtbase); 
     if (clazzNBTTagList.isAssignableFrom(nbtbase.getClass()))
       return new NBTTagList(nbtbase); 
     if (clazzNBTTagCompound.isAssignableFrom(nbtbase.getClass()))
       return new NBTTagCompound(nbtbase); 
     if (clazzNBTBase.isAssignableFrom(nbtbase.getClass()))
       return new NBTBase(nbtbase); 
     throw new IllegalArgumentException();
   }
 }


/* Location:              D:\User\Xuan\Downloads\MyBackpack1.2.5.jar!\net\saralab\mybackpac\\util\simplenbt\Reflector.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       1.1.3
 */